home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Superior F198925222001.psc / modFileExists.bas < prev    next >
Encoding:
BASIC Source File  |  2001-05-19  |  908 b   |  37 lines

  1. Attribute VB_Name = "modFileExists"
  2. ' by Rudy Alex Kohn (i think :)
  3. ' Returns TRUE if file exists, FALSE if not
  4.  
  5. Option Explicit
  6.  
  7. Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
  8.  
  9. Private Const OFS_MAXPATHNAME = 128
  10. Private Const OF_EXIST = &H4000
  11. Private Const FILE_NOT_FOUND = 2
  12.  
  13. Private Type OFSTRUCT
  14.   cBytes As Byte
  15.   fFixedDisk As Byte
  16.   nErrCode As Integer
  17.   Reserved1 As Integer
  18.   Reserved2 As Integer
  19.   szPathName(OFS_MAXPATHNAME) As Byte
  20. End Type
  21.  
  22. Function FileExists(FileName As String) As Long
  23.   Dim RetCode As Long
  24.   Dim OpenFileStructure As OFSTRUCT
  25.  
  26.   RetCode = OpenFile(FileName$, OpenFileStructure, OF_EXIST)
  27.  
  28.   Select Case OpenFileStructure.nErrCode
  29.     Case FILE_NOT_FOUND
  30.         FileExists = False
  31.     Case Else
  32.         FileExists = True
  33.   End Select
  34.  
  35. End Function
  36.  
  37.